<%
' +----------------------------------------------------------------------
' | POPASP [ ASP MVC ]
' +----------------------------------------------------------------------
' | Copyright (c) 2016 http://popasp.com All rights reserved.
' +----------------------------------------------------------------------
' | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
' +----------------------------------------------------------------------
' | Author: popasp <1737025626@qq.com>
' +----------------------------------------------------------------------
Class POPASP_URL
	private ctrlName
	private actionName
	
	Public Sub setConfig( attr,value )
		if isNumeric(value) then
			Execute attr & " = " & value
		else
			Execute attr & " = """ & value & """"
		end if
	end sub

	'将字符串首字母大写，popjb.com增加
	Private Function UCFirst(ByVal string)
		Dim first
		first = Mid(string,1,1)
		UCFirst = UCase(Mid(string,1,1)) & Mid(string,2)
	End Function  

	'获取控制器名称
	Function get_ctrl_name ( )
		dim c		
		if isEmpty( ctrlName ) then		
			c = Request.QueryString( C_("VAR_MODULE") )
			if not isEmpty(c) Then
			  c = trim( CStr(c) )
			End if
			if isEmpty(c) Then
			  c = C_("DEFAULT_MODULE")
			else
			  c = UCFirst(LCase(c))
			end if
			get_ctrl_name = c
		else
			get_ctrl_name = ctrlName
		end if
	End Function
	
	'获取操作方法名称
	Function get_action_name ( )
		dim a	
		if isEmpty( actionName ) then
			a = Request.QueryString( C_("VAR_ACTION") )
			if not isEmpty(a) Then
			  a = trim( CStr(a) )
			End if
			if isEmpty(a) Then
			  a = C_("DEFAULT_ACTION")
			end if
			get_action_name = a
		else
			get_action_name = actionName
		end if
	End Function	
	
	Sub set_tmpl_config
		dim script_name,pos
		dim c,a
		c = get_ctrl_name()
		a = get_action_name()
	
		'设置模板替换变量
		script_name = Request.ServerVariables("SCRIPT_NAME")		
		pos = instrrev(script_name,"/")
		if pos > 0 then
			POP_MVC.config("TMPL_PARSE_STRING")("__ROOT__") = left(script_name,pos-1)
		else
			POP_MVC.config("TMPL_PARSE_STRING")("__ROOT__") = ""
		end if
		
		if POP_MVC.config("TMPL_PARSE_STRING")("__APP__") = "" then
			POP_MVC.config("TMPL_PARSE_STRING")("__APP__") = script_name
		end if
		
		if POP_MVC.config("TMPL_PARSE_STRING")("__URL__") = "" then
			POP_MVC.config("TMPL_PARSE_STRING")("__URL__") = POP_MVC.config("TMPL_PARSE_STRING")("__APP__") & "?" & C_("VAR_MODULE") & "=" & c
		end if
		
		if POP_MVC.config("TMPL_PARSE_STRING")("__ACTION__") = "" then
			pos = inStr( POP_MVC.config("TMPL_PARSE_STRING")("__URL__") , "?" )
			if pos > 0 then
				if pos <> len( POP_MVC.config("TMPL_PARSE_STRING")("__URL__") ) then
					POP_MVC.config("TMPL_PARSE_STRING")("__ACTION__") = POP_MVC.config("TMPL_PARSE_STRING")("__URL__") & "&" & C_("VAR_ACTION") & "=" & a
				else
					POP_MVC.config("TMPL_PARSE_STRING")("__ACTION__") = POP_MVC.config("TMPL_PARSE_STRING")("__URL__") & C_("VAR_ACTION") & "=" & a
				end if
			else 
				POP_MVC.config("TMPL_PARSE_STRING")("__ACTION__") = POP_MVC.config("TMPL_PARSE_STRING")("__URL__") & "?" & C_("VAR_ACTION") & "=" & a
			end if
		end if

		if POP_MVC.config("TMPL_PARSE_STRING")("__SELF__") = "" then		
			POP_MVC.config("TMPL_PARSE_STRING")("__SELF__") = POP_MVC.config("TMPL_PARSE_STRING")("__APP__") & "?" &  Request.ServerVariables("QUERY_STRING")
		end if

		if POP_MVC.config("TMPL_PARSE_STRING")("__PUBLIC__") = "" then
			POP_MVC.config("TMPL_PARSE_STRING")("__PUBLIC__") = POP_MVC.config("TMPL_PARSE_STRING")("__ROOT__") & "/Public"
		end if
		if POP_MVC.config("TMPL_PARSE_STRING")("__UPLOAD__") = "" then
			POP_MVC.config("TMPL_PARSE_STRING")("__UPLOAD__") = POP_MVC.config("TMPL_PARSE_STRING")("__ROOT__") & "/Upload"
		end if	
	
	end sub
	
End Class
%>